package com.adkun.community.dao;

import com.adkun.community.entity.LoginTicket;
import org.apache.ibatis.annotations.*;

@Mapper
@Deprecated
public interface LoginTicketMapper {

    // 插入凭证
    @Insert({
            "insert into login_ticket(user_id,ticket,status,expired) ",
            "values(#{userId},#{ticket},#{status},#{expired})"
    })
    // 注意加空格，前后会自动拼在一起
    @Options(useGeneratedKeys = true, keyProperty = "id")
    // 由于我们没有插入id，但表里设置了id是AI的，所以要设定
    int insertLoginTicket(LoginTicket loginTicket);

    // 将登录信息放到数据库，然后将ticket发给浏览器
    @Select({
            "select id,user_id,ticket,status,expired ",
            "from login_ticket ",
            "where ticket=#{ticket}"
    })
    LoginTicket selectByTicket(String ticket);

    //修改凭证状态，退出改状态，一般不删除
    @Update({
            "<script>",
            "update login_ticket set status=#{status} where ticket=#{ticket}",
            "<if test=\"ticket!=null\">",
            "and 1=1 ",
            "</if>",
            "</script>"
    })
    // 演示要使用<if>标签，需要加上<script>
    int updateStatus(String ticket, int status);
}